<?php
include ('../../__global.php');

class search_gd extends ml_controller {
    
    private $searchKey;
    private $searchSort;
    private $page;
    private $block;
    private $aid;
    
    function initParam(){
        
        $this->searchKey = $this->input('searchKey', '', '');
        $this->searchSort = $this->input('sort','','hot');
        $this->page = intval($this->input('page' , '' , 1));
        if (1 > $this->page )
            $this->page = 1;
        
        $this->block = ($this->page-1)*3;
        $this->aid = $this->__visitor['uid'];
    }
    
    function checkParam(){
        
        $this->searchKey = Tool_antiXss::clean_danger_param(trim($this->searchKey));
        
    }
    
    function main(){

        //行为LOG
        $ext = array(
            'page' => $this->page,
            'order' => $this->searchSort,
        );
        ml_tool_actionlog::view_search($this->__visitor['uid'] , 'gd' , $this->searchKey , $ext);
        
        $oSearch = new ml_biz_search_gd($this->searchKey, $this->aid, $this->block);
        $oSearch->setSearchSort($this->searchSort);
        $aHtml = $oSearch->getSearchResult();
        
        $total_block = $oSearch->get_total_block();
        $total_number = $oSearch->get_total_number();
        
        $this->searchKey = Tool_string::un_html($this->searchKey);
        
        $data=array();
        foreach ($aHtml as $k => $v) {
            switch ($k%4) {
                case 0: $data['pins'][0][] = $v;    break;
                case 1: $data['pins'][1][] = $v;    break;
                case 2: $data['pins'][2][] = $v;    break;
                case 3: $data['pins'][3][] = $v;    break;
            }

        }
        $data['searchKey'] = $this->searchKey;
        $data['searchSort'] = $this->searchSort;
        $data['total_number'] = $total_number;
        
        
        

        $this->set_scope_var('$totalPage' , ceil($total_block / 3));
        $this->set_scope_var('$currentPage' , $this->page);
        $this->set_scope_var('$segment' , 0);
        $this->set_scope_var('$lastSegment' , $this->block == $total_block - 1 ? true : false);
        $this->set_scope_var('$searchKey' , $this->searchKey);    
        
        $title = $data['searchKey']. ' - 内容搜索';
        $this->set_page_title($title);
        
        $this->page_output('search::search_gd', $data);
    }
    
}

new search_gd();